package io.wongd.lib_douyin.db

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.TypeConverters

private var db: DouyinDB? = null

private fun requireDB(context: Context): DouyinDB {
    return db ?: Room.databaseBuilder(
        context,
        DouyinDB::class.java,
        "database-douyin"
    ).build().apply { db = this }
}

fun Context.requireDouyinDB() = requireDB(this)

@Database(entities = [DouyinBean::class], version = 1, exportSchema = false)
@TypeConverters(Converters::class)
abstract class DouyinDB : RoomDatabase() {
    abstract fun douyinDao(): DouyinDao
}